package com.fsj.miniapp.service.impl;

import com.fsj.miniapp.entity.GoodsPic;
import com.fsj.miniapp.service.GoodsPicService;
import com.fsj.miniapp.vo.GoodsPicVo;
import com.google.common.collect.Lists;
import com.stip.mybatis.generator.plugin.BaseExample;
import com.stip.mybatis.generator.plugin.BaseService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class GoodsPicServiceImpl extends BaseService<GoodsPic, BaseExample, Long> implements GoodsPicService {
    @Override
    public List<GoodsPicVo> getById(Long goodsId) {



        BaseExample exam = new BaseExample();

        exam.createCriteria().addCriterion("goods_id=", goodsId);
        exam.setOrderByClause(" sorted asc");

        List<GoodsPic> goodsPics = selectByExample(exam);

        if (!CollectionUtils.isEmpty(goodsPics)) {

            return goodsPics.stream().map(f -> {
                GoodsPicVo vo = new GoodsPicVo();
                BeanUtils.copyProperties(f, vo);
                return vo;
            }).collect(Collectors.toList());
        }

        return Lists.newArrayList();
    }
}